package package007

import fundation.gsonPrintln
import org.junit.Test


/**
 * @author futao
 * Created on 2017/11/13 - 20:52.
 */
/**
 * 重载算术运算符
 */
data class Point(var x: Int, var y: Int) : Comparable<Point> {

    /**
     * 排序
     */
    override fun compareTo(other: Point): Int = compareValuesBy(this, other, Point::x)

    /**
     * 重载二元运算符-加法
     */
    operator fun plus(point: Point): Point = Point(x + point.x, y + point.y)

    /**
     * 重载二元运算符-除法
     */
    operator fun div(point: Point): Point = Point(x / point.x, y / point.y)

    operator fun plusAssign(point: Point) {
        Point(x.plus(point.x), y.plus(point.y))
    }

    override fun equals(other: Any?): Boolean {
        return super.equals(other)
    }

    operator fun Point.get(index: Int): Int = when (index) {
        0 -> this.x
        1 -> this.y
        else ->
            throw Exception("")
    }

    operator fun Point.set(indexX: Int, indexY: Int) {
        this.x = indexX
        this.y = indexY
    }
}


class TestClass2 {
    fun testCase004() {
        val point = Point(1000, 1000)
    }

    @Test
    fun testCase003() {
        val point = Point(111, 222)
//        point.get()
//        point[0]
        val p = Point(1, 1)
//        p.set(100,100)
        println("ppppppppppppp" + p)
    }

    @Test
    fun a() {
        val p = Point(22, 22).plus(Point(33, 33))
        val p2 = Point(22, 22).plus(Point(33, 0))
        gsonPrintln(p)
        val point = Point(12, 25) / Point(4, 5)
        gsonPrintln(point)
        gsonPrintln("1111111" + p.component1())
        println("1111111=====" + p.component1())
        gsonPrintln(55.compareTo(10))
        gsonPrintln(55.compareTo(60))
        gsonPrintln(55.compareTo(55))
        gsonPrintln("0.0000...." + p.compareTo(p2))
    }
}

